#include <fstream>
#include <sstream>
#include <iostream>
#include <opencv2/dnn.hpp>


struct Net_config
{
	float confThreshold; // class Confidence threshold
	float nmsThreshold;  // Non-maximum suppression threshold
	float objThreshold;  //Object Confidence threshold
    std::string netname;
};


struct YoloReslut
{
    int class_id;
    float confidence;
    cv::Rect box;
};

class YOLO
{
public:
    YOLO();
    void detect(cv::Mat& frame);
    void detect(cv::Mat &frame, std::vector<YoloReslut>& resluts);
    void get_people_reslut(std::vector<YoloReslut> in_res, std::vector<YoloReslut>& out_res);

private:
    const float anchors[3][6] = {{10.0, 13.0, 16.0, 30.0, 33.0, 23.0}, {30.0, 61.0, 62.0, 45.0, 59.0, 119.0},{116.0, 90.0, 156.0, 198.0, 373.0, 326.0}};
    const float stride[3] = { 8.0, 16.0, 32.0 };
    const std::string classesFile = "./chargeRobot/model/coco.names";
    const std::string netFile = "./chargeRobot/model/yolov5l.onnx";
    const int inpWidth = 640;
    const int inpHeight = 640;
    float confThreshold;
    float nmsThreshold;
    float objThreshold;

    char netname[20];
    std::vector<std::string> classes;
    cv::dnn::Net net;
    void drawPred(int classId, float conf, int left, int top, int right, int bottom, cv::Mat& frame);
    void sigmoid(cv::Mat* out, int length);
};

static inline float sigmoid_x(float x)
{
	return static_cast<float>(1.f / (1.f + exp(-x)));
}


